// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 6852 of the Stellaris Firmware Development Package.
//
//*****************************************************************************

#include "timers.h"
#include "OS.h"


extern void (*func_array[3])(void);


//*****************************************************************************
//
//! \addgroup OS
//! Timer1 Interrupt handler used if thread 1 is activated
//! Executes the function from the funciton pointer array used in the initialization
//! of OS_AddPeriodicThread
//
//*****************************************************************************
void Timer1IntHandler(void) {
	 TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
	
	(*func_array[0])();

}

//*****************************************************************************
//
//! \addgroup OS
//! Timer2 Interrupt handler used if thread 2 is activated
//! Executes the function from the funciton pointer array used in the initialization
//! of OS_AddPeriodicThread
//! a global timer ms counter is also incremented periodically in the function
//
//*****************************************************************************
void Timer2IntHandler(void) {
	 TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
	(*func_array[1])();
}





//*****************************************************************************
//
// Initializes the Systick interrupt
// This also triggers a thread switch
//
//*****************************************************************************

void SysTickInit(int period) {
	//
    // Set up the period for the SysTick timer.  The SysTick timer period will
    // be equal to the system clock / 1000, resulting in a period of 1 ms.
    //
    SysTickPeriodSet(period * (SysCtlClockGet()/1000));
	
	 //
    // Enable interrupts to the processor.
    //
   // IntMasterEnable();
	//
    // Enable the SysTick Interrupt.
    //
    SysTickIntEnable();
		
	//
    // Enable SysTick.
    //
    SysTickEnable();


}
